﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BattleThis.Core
{

	/// <summary>
	/// Determines the different Landscape on the game map.
	/// </summary>
	public class Landscape
	{

		#region Variablen
		public enum Characteristics { Grass = 0, Mounten = 1, Sea = 2 }
		public static Dictionary<Characteristics, Landscape> Map = InitalizeMap();

		public static readonly Landscape Default = Map[ Characteristics.Grass ];
		public static readonly Landscape Mounten = Map[ Characteristics.Mounten ];
		public static readonly Landscape Sea = Map[ Characteristics.Sea ];

		#endregion

		#region Properties
		/// <summary>
		/// Gets the movement costs  to enter this landscape.
		/// </summary>
		public int MovementCosts { get; protected set; }

		/// <summary>
		/// Gets or sets the defence bonus.
		/// </summary>
		/// <value>
		/// The defence bonus.
		/// </value>
		public int DefenceBonus { get; protected set; }

		#endregion

		#region Methoden

		/// <summary>
		/// Initalizes the internale map.
		/// </summary>
		/// <returns></returns>
		private static Dictionary<Characteristics, Landscape> InitalizeMap()
		{
			var map = new Dictionary<Characteristics, Landscape>();
			var defaultItem = new Landscape( 1, 0 );
			var mounten = new Landscape( 10, 1 );
			var see = new Landscape( 20, 0 );

			map.Add( Characteristics.Grass, defaultItem );
			map.Add( Characteristics.Mounten, mounten );
			map.Add( Characteristics.Sea, see );


			return map;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Landscape"/> class.
		/// </summary>
		/// <param name="costs">The movement factor.</param>
		internal protected Landscape( int costs, int defenceBonus )
		{
			if( costs < 0 )throw new ArgumentOutOfRangeException( "costs < 0" );

			this.MovementCosts = costs;
			this.DefenceBonus = defenceBonus;
		}

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return Map.Where( x => this.Equals( x.Value ) ).Single().Key.ToString();
		}
		#endregion

	}
}